<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>

<%@ page import="com.msmall.base.util.ConstantDB" language="java"%>
<c:set var="AVALIABLE" value="<%=ConstantDB.AVALIABLE%>"></c:set>
<c:set var="UNAVALIABLE" value="<%=ConstantDB.UNAVALIABLE%>"></c:set>
<c:set var="REPLY" value="<%=ConstantDB.REPLY%>"></c:set>
<c:set var="UNREPLY" value="<%=ConstantDB.UNREPLY%>"></c:set>
<c:set var="REPLY" value="<%=ConstantDB.REPLY%>"></c:set>
<c:set var="UNREPLY" value="<%=ConstantDB.UNREPLY%>"></c:set>
<c:set var="FROM_TRANSFER" value="<%=ConstantDB.FROM_TRANSFER%>"></c:set>
<c:set var="FROM_ORIGINAL" value="<%=ConstantDB.FROM_ORIGINAL%>"></c:set>

<div class="dirbar">
	<a href="<c:url value='/home.do'/>"><span>首页</span></a> >> 发表文章
</div>	
<div class="ntopic">
	<div class="ntopic_auther">
		<span>作&nbsp;&nbsp;者:</span><c:out value="${nickname}"></c:out>
	</div>
	<form id="f_new_article" action="<c:url value='/klg/article/save.do'/>" method="POST" >
		<input type="hidden" name="bid" value="${bid }"/>
		<span>标&nbsp;&nbsp;题:</span>
		<input id="article_title" name="article.title" value="${article.title}" size="40" class="input"/>
		&nbsp;&nbsp;
		<select name="article.original" size="1" class="input">
			<option value="${FROM_ORIGINAL}" <c:if test="${article.original == FROM_ORIGINAL}">selected="selected"</c:if>>原创</option>
			<option value="${FROM_TRANSFER}" <c:if test="${article.original == FROM_TRANSFER}">selected="selected"</c:if>>转载</option>
		</select>
		<br/>
		<span>分&nbsp;&nbsp;类:</span>
			<select id="parentType" name="parentType"></select>
			<select id="valueType" name="valueType"></select>
		<br/>
		<span>摘&nbsp;&nbsp;要: 300字以内，无HTML/CSS格式</span>
		<textarea name="article.contentAbstract" rows="10" cols="80"><c:out value='${article.contentAbstract}'/></textarea>
		<br/>
		<span>内&nbsp;&nbsp;容:</span>
		<br/>
		<c:if test="${not empty message}">
			<div id="div_article_error" class="div_topic_error" style="display:block"><c:out value="${message}"/></div>
		</c:if>
		<textarea id="article_content" name="article.content" rows="200" cols="80" style="width:750px;height:400px"><c:out value='${article.content}'/></textarea>
		<br/>
		<span>是否可以回复:</span>
		<input type="checkbox" id="f_article_reply" name="article.reply" value="${REPLY}"/>
		<script type="text/javascript">
			var articlereply = "<c:out value='${article.reply}' />";
			var articlereplyValue = parseInt(articlereply);
			if(articleEnabledValue == 1){
				$("#f_article_reply").attr("checked",true);
		  	}
		</script>
		<br/>
		<button class="btn1" type="submit" name="submitTopic">发表</button>
	</form>
</div>
<script type="text/javascript">
KE.show({
	id : 'article_content',
	imageUploadJson : ctx+'/h/keditor.do',
	fileManagerJson : ctx + '/editor/jsp/file_manager_json.jsp',
	allowFileManager : true,
	afterCreate : function(id) {
		KE.event.ctrl(document, 13, function() {
			KE.util.setData(id);
			document.forms['article_content'].submit();
		});
		KE.event.ctrl(KE.g[id].iframeDoc, 13, function() {
			KE.util.setData(id);
			document.forms['article_content'].submit();
		});
	}
});

$(document).ready(function(){
	var url = ctx + '/json/segment/get.do?module=klg&level=1';
	$.getJSON(url, function(data){
		for(var i=0; i<data.segments.length;i++){
			$('#parentType').append('<option value='+data.segments[i].value+'>'+data.segments[i].text+'</option>');
		}
	});
	$('#parentType').change(function(){
		var id=$("#parentType").val();
		var url = ctx + '/json/segment/get.do?module=klg&level=2&id='+id;
		$('#valueType').html('');
		$.getJSON(url, function(data){
			for(var i=0; i<data.segments.length;i++){
				$('#valueType').append('<option value='+data.segments[i].value+'>'+data.segments[i].text+'</option>');
			}
		});
	});
	setTimeout(function(){
       $("#parentType").trigger('change');
    }, 1000);
});
</script>